/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * frmAltadeBanco.java
 *
 * Created on 24/07/2012, 03:23:01 PM
 */

package Bancos;

import Beans.BancoBean;
import Blogic.BancoBLogic;
import java.util.Vector;
import javax.swing.JOptionPane;

/**
 *
 * @author orellana
 */
public class frmAltadeBanco extends javax.swing.JFrame {

    public int tipoAccion=0;
    private String idBanco="";

    /** Creates new form frmAltadeBanco */
    public frmAltadeBanco (int tipo) {
        initComponents();
        // Posicion del Formualrio
        this.setLocationRelativeTo(null);
        // Definimos el Redimensionamiento
        this.setResizable(false);
        // Definimos el Cerrado del Formlario
        this.setDefaultCloseOperation(HIDE_ON_CLOSE);
        // Seteamos el Titulo del Formulario
        switch (tipo){
            // Alta de Categoria
            case 1:
                this.setTitle(" .:: Alta de Banco ::.");
                jTabbedPane1.setTitleAt(0,"Alta de Bancos");
               
                this.tipoAccion=1;
                break;
            // Modificación de Categoria
            case 2:
                this.setTitle(".:: Modificar Banco ::.");
                jTabbedPane1.setTitleAt(0,"Modificar Banco");
                this.tipoAccion=2;
                break;
        }
    }

    // Seteamos el Identificador dela Categoria
    public void setIdBanco(String idBanco){
        this.idBanco=idBanco;
    }

    // Obtenemos los Datos del banco
    //String idCategoria
    public void obtDatosBanco(){
        // Variables locales
        Vector datosBanco=new Vector();
        BancoBean sqlBean=new BancoBean();
        BancoBean detalleDatosBanco=new BancoBean();
         //System.out.println("entre akkii obt cat"+idCategoria);
        // Datos banco
        // Seteamos los Datos
        sqlBean.setIdBanco(idBanco);
        // Realizamos la consulta
        datosBanco=(new BancoBLogic()).getDatosBanco(sqlBean);
        detalleDatosBanco=(BancoBean) datosBanco.elementAt(0);
        // Vaciamos los Datos
        jTextField1.setText(detalleDatosBanco.getNombreBanco());
        jTextField2.setText(detalleDatosBanco.getDescripcionBanco());
    }

public void altaClickBanco(){

     BancoBean sqlBean=new BancoBean();
        Vector datosBanco=new Vector();
        // Pasamos de minuscula a mayuscula
        jTextField1.setText(jTextField1.getText().toUpperCase());
        jTextField2.setText(jTextField2.getText().toUpperCase());
        // Validamos el tipo de accion a realizar
        switch (this.tipoAccion){
            // Alta de categoria
            case 1:
                // Variables locales


                // Validacion de campos
                if(jTextField1.getText().equalsIgnoreCase("")){
                    // Nombre
                    // Mensaje del usuario
                    JOptionPane.showMessageDialog(null,"Capture el Nombre del Banco","Validacion",JOptionPane.INFORMATION_MESSAGE);
                    // Movemos el foco
                    jTextField1.requestFocus();
                }else if(jTextField2.getText().equalsIgnoreCase("")){
                    // Descripcion
                    // Mensaje del usuario
                    JOptionPane.showMessageDialog(null,"Capture la Descripcion del Banco","Validacion",JOptionPane.INFORMATION_MESSAGE);
                }else{
                    // Guarda registro de Banco
                    // Seteamos los datos
                    sqlBean.setNombreBanco(jTextField1.getText());
                    sqlBean.setDescripcionBanco(jTextField2.getText());

                    // Insertamos el registro
                    datosBanco=(new BancoBLogic()).execute(sqlBean);
                    // Evaluamos el resultado
                    if (datosBanco.elementAt(0).equals("OK")){
                        // Mensaje al usuario
                        JOptionPane.showMessageDialog(null,"Banco Registrado Satisfactoriamente","Registro",JOptionPane.INFORMATION_MESSAGE);
                        jTextField1.setText("");
                        jTextField2.setText("");
                        this.setVisible(false);
                    } else{
                        // Mensaje de error
                        JOptionPane.showMessageDialog(null,"Ocurrio un Problema al Momento de Registrar el Banco","Registro",JOptionPane.INFORMATION_MESSAGE);
                    }
                }
                break;

                // Modificar banco
            case 2:
            //Validacion de campos
                //System.out.println("entre en guardar cambios");
                  if(jTextField1.getText().equalsIgnoreCase("")){
                    // Nombre
                    // Mensaje del usuario
                    JOptionPane.showMessageDialog(null,"Capture el Nombre del Banco","Validacion",JOptionPane.INFORMATION_MESSAGE);
                    // Movemos el foco
                    jTextField1.requestFocus();
                }else if(jTextField2.getText().equalsIgnoreCase("")){
                    // Descripcion
                    // Mensaje del usuario
                    JOptionPane.showMessageDialog(null,"Capture la Descripcion del Banco","Validacion",JOptionPane.INFORMATION_MESSAGE);
                 }else{
                    // Guarda registro de banco
                    // Seteamos los datos
                    sqlBean.setIdBanco(idBanco);
                    sqlBean.setNombreBanco(jTextField1.getText());
                    sqlBean.setDescripcionBanco(jTextField2.getText());

                    // actualizamos el registro
                    datosBanco=(new BancoBLogic()).updateDatosBanco(sqlBean);
                    // Evaluamos el resultado
                    if (datosBanco.elementAt(0).equals("OK")){
                        // Mensaje al usuario
                        JOptionPane.showMessageDialog(null,"Banco Actualizada Satisfactoriamente","Actualizacion",JOptionPane.INFORMATION_MESSAGE);
                        jTextField1.setEnabled(false);
                        jTextField2.setEnabled(false);

                    } else{
                        // Mensaje de error
                        JOptionPane.showMessageDialog(null,"Ocurrio un Problema al Momento de Actualizar el Banco","Actualizacion",JOptionPane.INFORMATION_MESSAGE);
                    }
                }
            break;
    }
}

 //   }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jToolBar1 = new javax.swing.JToolBar();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setName("Form"); // NOI18N

        jToolBar1.setFloatable(false);
        jToolBar1.setRollover(true);
        jToolBar1.setName("jToolBar1"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(sistemapegasso.SistemaPegassoApp.class).getContext().getResourceMap(frmAltadeBanco.class);
        jButton1.setIcon(resourceMap.getIcon("btnGuardar.icon")); // NOI18N
        jButton1.setText(resourceMap.getString("btnGuardar.text")); // NOI18N
        jButton1.setToolTipText(resourceMap.getString("btnGuardar.toolTipText")); // NOI18N
        jButton1.setFocusable(false);
        jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton1.setName("btnGuardar"); // NOI18N
        jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jButton1);

        jButton2.setIcon(resourceMap.getIcon("btnCerrar.icon")); // NOI18N
        jButton2.setText(resourceMap.getString("btnCerrar.text")); // NOI18N
        jButton2.setToolTipText(resourceMap.getString("btnCerrar.toolTipText")); // NOI18N
        jButton2.setFocusable(false);
        jButton2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton2.setName("btnCerrar"); // NOI18N
        jButton2.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jButton2);

        jTabbedPane1.setName("jtpBanco"); // NOI18N

        jPanel1.setName("jPanel1"); // NOI18N

        jLabel1.setBackground(resourceMap.getColor("jLabel1.background")); // NOI18N
        jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
        jLabel1.setForeground(resourceMap.getColor("jLabel1.foreground")); // NOI18N
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N
        jLabel1.setOpaque(true);

        jLabel2.setFont(resourceMap.getFont("jLabel2.font")); // NOI18N
        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jTextField1.setFont(resourceMap.getFont("txtNombre.font")); // NOI18N
        jTextField1.setText(resourceMap.getString("txtNombre.text")); // NOI18N
        jTextField1.setName("txtNombre"); // NOI18N
        jTextField1.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTextField1FocusLost(evt);
            }
        });

        jLabel3.setFont(resourceMap.getFont("jLabel3.font")); // NOI18N
        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jTextField2.setFont(resourceMap.getFont("txtDescripcion.font")); // NOI18N
        jTextField2.setText(resourceMap.getString("txtDescripcion.text")); // NOI18N
        jTextField2.setName("txtDescripcion"); // NOI18N
        jTextField2.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTextField2FocusLost(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jTextField1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 376, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE))
                .addContainerGap())
            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 483, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab(resourceMap.getString("jPanel1.TabConstraints.tabTitle"), jPanel1); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 512, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 488, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTextField1FocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextField1FocusLost
        // TODO add your handling code here:
         // Para pasar de miniscula a mayuscula
        jTextField1.setText(jTextField1.getText().toUpperCase());
    }//GEN-LAST:event_jTextField1FocusLost

    private void jTextField2FocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextField2FocusLost
        // TODO add your handling code here:
         // Para pasar de miniscula a mayuscula
        jTextField2.setText(jTextField2.getText().toUpperCase());
    }//GEN-LAST:event_jTextField2FocusLost

    /**
    * @param args the command line arguments
    */
//    public static void main(String args[]) {
//        java.awt.EventQueue.invokeLater(new Runnable() {
//            public void run() {
//                new frmAltadeBanco().setVisible(true);
//            }
//        });
//    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    public javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JToolBar jToolBar1;
    // End of variables declaration//GEN-END:variables

}
